package com.example.myapplication.tack_15.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_11.data.ListData;
import com.example.myapplication.tack_15.LawyerActivity;
import com.example.myapplication.tack_15.LawyerQXActivity;
import com.example.myapplication.tack_15.data.ArrangeData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class ArrangeAdapter extends RecyclerView.Adapter<ArrangeAdapter.My> {
    private List<ArrangeData.RowsDTO> list;
    private Context context;
    private View view;
    private List<ArrangeData.RowsDTO> listArrange;
    public ArrangeAdapter(List<ArrangeData.RowsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.tack_15_list,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        Glide.with(context).load(OkHttpTool.URL + list.get(position).getAvatarUrl()).into(holder.avatarUrl);
        holder.name.setText(list.get(position).getName());
        if(context instanceof LawyerQXActivity){
            holder.workStartAt.setText("联系方式：:"+list.get(position).getLicenseNo());
        }else{
            holder.workStartAt.setText("工作起始时间:"+list.get(position).getWorkStartAt());
        }

        holder.legalExpertiseName.setText("法律专长"+list.get(position).getLegalExpertiseName());
        String substring = list.get(position).getBaseInfo().substring(0, 10)+"...";
        holder.baseInfo.setText(substring);
        holder.line.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, LawyerQXActivity.class);
                intent.putExtra(Common.COMMON,String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        if(context instanceof LawyerQXActivity){
            return list != null?1:0;
        }else{
            return list != null?10:0;
        }

    }

    public class My extends RecyclerView.ViewHolder{
        private ImageView avatarUrl;
        private TextView name;
        private TextView workStartAt;
        private TextView legalExpertiseName;
        private TextView baseInfo;

        private LinearLayout line;
        public My(@NonNull View itemView) {
            super(itemView);
            avatarUrl = view.findViewById(R.id.avatarUrl);
            baseInfo = view.findViewById(R.id.baseInfo);
            name = view.findViewById(R.id.name);
            workStartAt = view.findViewById(R.id.workStartAt);
            legalExpertiseName = view.findViewById(R.id.legalExpertiseName);

            line = view.findViewById(R.id.line);
        }
    }
}
